import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { OrderVO, OrderForm, OrderQuery } from '@/api/order/types';

/**
 * 查询订单主（客户ID和供应商ID必须二选一，由应用程序保证）列表
 * @param query
 * @returns {*}
 */

export const listOrder = (query?: OrderQuery): AxiosPromise<OrderVO[]> => {
  return request({
    url: '/admin/order/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询订单主（客户ID和供应商ID必须二选一，由应用程序保证）详细
 * @param id
 */
export const getOrder = (id: string | number): AxiosPromise<OrderVO> => {
  return request({
    url: '/company/order/' + id,
    method: 'get'
  });
};

/**
 * 新增订单主（客户ID和供应商ID必须二选一，由应用程序保证）
 * @param data
 */
export const addOrder = (data: OrderForm) => {
  return request({
    url: '/admin/order',
    method: 'post',
    data: data
  });
};

/**
 * 修改订单主（客户ID和供应商ID必须二选一，由应用程序保证）
 * @param data
 */
export const updateOrder = (data: OrderForm) => {
  return request({
    url: '/admin/order',
    method: 'put',
    data: data
  });
};

/**
 * 删除订单主（客户ID和供应商ID必须二选一，由应用程序保证）
 * @param id
 */
export const delOrder = (id: string | number | Array<string | number>) => {
  return request({
    url: '/admin/order/' + id,
    method: 'delete'
  });
};


/**
 * 查询订单信息列表
 * @param query
 * @returns {*}
 */
export const myOrderList = (query) => {
  return request({
    url: '/company/order/myOrderList',
    method: 'get',
    params: query
  });
};

/**
 * 新增订单信息
 * @param data
 */
export const myAddOrder = (data) => {
  return request({
    url: '/company/order',
    method: 'post',
    data: data
  });
};

/**
 * 查询订单号
 * @param query
 * @returns {*}
 */
export const getOrderNo = (query) => {
  return request({
    url: '/company/order/getOrderNo',
    method: 'get',
    params: query
  });
};

/**
 * 查询订单主（客户ID和供应商ID必须二选一，由应用程序保证）摘要信息
 * @param query
 * @returns {*}
 */
export const getOrderSummary = (query) => {
  return request({
    url: '/company/home/summary',
    method: 'get',
    params: query
  });
};

/**
 * 删除订单主（客户ID和供应商ID必须二选一，由应用程序保证）
 * @param ids
 */
export const delMyAddress = (ids: string | number | Array<string | number>) => {
  return request({
    url: '/company/address/' + ids,
    method: 'delete'
  });
};


/**
 * 作废订单主（客户ID和供应商ID必须二选一，由应用程序保证）
 * @param orderId
 */
export const cancelOrder = (orderId: string | number) => {
  return request({
    url: '/company/order/cancel/' + orderId,
    method: 'put'
  });
};
